/*
 * Copyright (C) 2025 Tsingteng MicroSystem
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef _NFC_CONFIG_API_H_
#define _NFC_CONFIG_API_H_
#ifndef NCI_CONFIG_MANAGER_DISABLE

#include "nfc_types.h"
#include "osi_types.h"

/** @brief 存储vendor config参数值类型 */
typedef struct {
    bool nfa_poll_bailout_mode;
    uint8_t offhost_route;
    uint8_t offhost_route_felica;
    uint8_t system_code_route;
    uint8_t system_code_power_state;
    uint8_t aid_route;
    uint8_t offhost_ese_pipe_id;
    uint8_t offhost_sim_pipe_id;
    uint32_t max_iso_dep_transceive_length;
    tNFC_CF_ARRAY host_allow_list;
    tNFC_CF_ARRAY offhost_route_uicc;
    tNFC_CF_ARRAY offhost_route_ese;
    uint8_t iso_dep_route;

    /* Max wait time for rAPDU/ATR on apdu gate */
    uint16_t max_apdu_wait_time;
    /* TMS NFCEE Power And Link setting for eSE */
    uint8_t nfcee_pl_cfg;
    uint8_t nfcee_pl_value;
    /* Set the T4TNfcee AID Power state */
    uint8_t t4t_nfcee_aid_power_state;
    /* T4T NFCEE ENABLE */
    uint8_t t4t_nfcee_enable;
    /* Enable/Disable setting all route when default payment changed */
    uint8_t set_all_route_default;
    /* Configure Tech route Mask for HCE */
    uint8_t default_hce_tech;
    /* Forcing HOST to listen for a selected protocol */
    uint8_t host_listen_tech_mask;
    tNFC_CF_ARRAY tms_forum_disable;
} tNFC_VENDOR_CONFIG;

/**
 * @brief 存储NFC配置参数值的结构体
 */
typedef struct {
    uint8_t nci_log_level;
    uint8_t polling_tech_mask;
    uint32_t nci_rsp_timeout;
    uint32_t nci_ntf_timeout;
    uint32_t nci_data_timeout;
    uint32_t rw_activate_timeout;
    uint8_t aid_pwr;
    uint16_t sys_code;
    uint8_t aid_match_mode;
    uint8_t tms_lx_debug_level;
    uint32_t max_rapdu_wait_time;
    bool t5t_mute_legacy;
    // tNFC_CF_ARRAY array_sample;    /**< 示例数组 */
    // char *string_sample;           /**< 示例字符串 */
    tNFC_VENDOR_CONFIG vendor_cf;
} tNFC_CF;

/**
 * @brief NFC配置信息管理结构体
 */
typedef struct {
    tNFC_CF cf; /**< 存储NFC配置的结构体 */
    void *cf_table; /**< NCI配置映射表 */
    void *vnd_cf_table; /**< vonder配置映射表 */
    void *vnd_ext_cf_table; /**< vonder扩展配置映射表 */
    size_t cf_table_len; /**< NCI配置映射表的长度 */
    size_t vnd_cf_table_len; /**< vonder配置映射表的长度 */
    size_t vnd_ext_cf_table_len; /**< vonder扩展配置映射表的长度 */
} tNFC_CONFIG_MANAGER;

/**
 * @brief 获取NFC配置对象
 *
 * @return 返回指向NFC配置对象的指针，如果获取失败则abort程序，返回NULL
 */
const tNFC_CF *nfc_config_get(void);

/**
 * @brief 重置配置状态，将其标记为未加载状态，以便在下一次获取配置时生效
 */
void nfc_config_reset(void);

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/**
 * @brief 检查指定的键值是否存在于配置中，并返回对应的值
 *
 * @param[in] key 配置项的键，用于在配置列表中查找对应的配置项
 * @param[out] pp_value 返回指向键对应配置项值的指针
 * @param[out] value_size 返回键对应配置项值大小的指针
 *
 * @return 如果成功找到配置项并复制其值，则返回true；否则返回false
 */
bool nfa_config_get_value_present(const tCF_KEY key, const void **pp_value, size_t *value_size);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* NCI_CONFIG_MANAGER_DISABLE */
#endif /* _NFC_CONFIG_API_H_ */
